<?php


namespace app\common\model\tang;

use app\common\impl\Comm;
use app\common\model\CommonBaseModel;

class WatchMaintain extends CommonBaseModel implements Comm
{

    public function getAdminPageData($param = [], $order = '',$where=[])
    {

        if (isset($param["merchant_id"]) && !empty($param['merchant_id'])) {
            $where[] = ["wm.merchant_id", "=", $param['merchant_id']];
        }
        if (isset($param['type']) && !empty($param['type'])) {
            $where[] = ["wm.type", "=", $param["type"]];
        }
        if (isset($param['use_type']) && !empty($param['use_type'])) {
            $where[] = ["wm.use_type", "=", $param["use_type"]];
        }
        if (isset($param['pointName']) && !empty($param['pointName'])) {
//            $where[] = ["wm.pointName", "like", ""$param["pointName"]];
            $where[] = ['wm.pointName','like',"%{$param['pointName']}%"];;

        }
        if (isset($param['pointId']) && !empty($param['pointId'])) {
            $where[] = ["wm.pointId", "like","%{$param['pointId']}%"];
        }
        if (isset($param['pointId'])&&$param['is_sole']!='') {
            $where[] = ["wm.is_sole", "=", $param["is_sole"]];
        }
        if (isset($param['is_normal']) && !empty($param['is_normal'])) {
            $where[] = ["wm.is_normal", "=", $param["is_normal"]];
        }
        if (isset($param['status']) && !empty($param['status'])) {
            $where[] = ["wm.status", "=", $param["status"]];
        }
        $data = $this
            ->alias('wm')
            ->leftjoin(['tang_merchant' => 'm'], "wm.merchant_id = m.id")
            ->where($where)
            ->field("m.name,m.company,wm.id,wm.type,wm.pointId,wm.pointName,wm.rate,wm.initial_degrees,wm.status,wm.use_type,wm.switching");
        $count = $data->count();
        $result =$data->page(PAGE)->order("wm.id desc")->limit(LIMIT)->select()->toArray();
        return parent::ajaxResult($result, $count);

    }
    public function merchant(){
        return $this->hasOne(Merchant::class,'id','merchant_id')->bind([
            'start_balance'=>'start_balance',
            'balance'=>'balance',
            'frozen_balance'=>'frozen_balance',
            'code'=>'code',
            'company'=>'company',
            'merchant_sn'=>'merchant_sn',
            'name'=>'name',
            'openid'=>'openid'
        ]);
    }

//    public function merchant(){
//
//        return $this->hasOne(Merchant::class,"id","merchant_id");
//    }
//    public function getUseTypeAttr($value,$data){
//        if($value){
//            $arr = [
//                1 => "写字楼自用",
//                2 => "写字楼公区",
//                3 => "写字楼商户",
//                4 => "商场自用",
//                5 => "商场公区",
//                6 => "商场商户"
//            ];
//            return $arr[$value];
//        }
//        return '';
//    }
    //读取器 状态字段
    public function getStatusAttr($value,$data){
        $arr = [
            1 => "正常",
            2 => "停用"
        ];
        return $arr[$value];
    }

//    //读取器 表类型字段（type）
//    public function getTypeAttr($value,$data){
//        $arr = [
//            1 => "水表",
//            2 => "电表"
//        ];
//        return $arr[$value];
//    }





    public function Refund($param = [], $order = 'id desc',$where =[]){


    }

    public function getAdminPageDatas($param = [], $order = 'id desc',$where=[])
    {

    }

    public function delById($id)
    {
        // TODO: Implement delById() method.
    }

    public function doAll($data)
    {
        // TODO: Implement doAll() method.
        return parent::doAllData($data);
    }


}